<?php
/**
*	系统里默认的users模块的
*/
namespace Rainrock\Framework\Module;


use Rainrock\Framework\kernel\core\ModuleInfo;
use Rainrock\Framework\kernel\core\ModuleFields;
use Rainrock\Framework\kernel\base\Rock;
use Rainrock\Framework\kernel\base\Jiami;

class UsersModuleInfo extends ModuleInfo{
	
	protected function initModule(){
		 $this->setName('用户');
		 $this->setNum('users');
		 
		 $this->addIndex('jian', 'user'); //user主键
		 
		 $this->addFields(ModuleFields::get('face')
			->setName('头像')
			->setLen(300)
			->setType('varchar')
			->setFieldstype('uploadimg')
		 );
		 
		 $this->addFields(ModuleFields::get('user')
			->setName('帐号')
			->setIsbt(1)
			->setIsonly(1)
			->setLen(30)
			->setSm('字母数字组合')
			->setType('varchar')
		 );
		 
		 $this->addFields(ModuleFields::get('name')
			->setName('姓名')
			->setIsbt(1)
			->setLen(30)
			->setType('varchar')
		 );
		 
		 $this->addFields(ModuleFields::get('mobile')
			->setName('手机号')
			->setIsonly(1)
			->setIsjm(1)
			->setLen(30)
			->setType('varchar')
		 );
		 
		 $this->addFields(ModuleFields::get('email')
			->setName('邮箱')
			->setIsonly(1)
			->setIslb(0)
			->setLen(100)
			->setType('varchar')
		 );
		 
		 $this->addFields(ModuleFields::get('pass')
			->setName('密码')
			->setLen(50)
			->setIslb(0)
			->setType('varchar')
			->setSm('默认123456,编辑时不写不修改')
		 );
		 
		 $this->addFields(ModuleFields::get('rand')
			->setName('随机数')
			->setLen(30)
			->setIslu(0)
			->setIslb(0)
			->setType('varchar')
		 );
		
		 
		 $this->addFields(ModuleFields::get('status')
			->setName('状态')
			->setLen(1)
			->setDev(1)
			->setData('0|停用,1|启用')
			->setIspx(1)
			->setIsbt(1)
			->setSm('启用用户')
			->setFieldstype('checkbox')
			->setType('tinyint')
		 );
		 
		 $this->addFields(ModuleFields::get('type')
			->setName('类型')
			->setLen(1)
			->setDev(0)
			->setIspx(1)
			->setData('0|普通,1|管理员,2|超级管理员')
			->setFieldstype('select')
			->setType('tinyint')
		 );
		 
		 $this->addFields(ModuleFields::get('ranking')
			->setName('职位')
			->setLen(100)
			->setIseditlx(1)
			->setType('varchar')
		 );
		 
		 $this->addFields(ModuleFields::get('sort')
			->setName('排序')
			->setDev(0)
			->setIspx(1)
			->setZdsm('数字越大越靠后')
			->setIseditlx(1)
			->setType('int')
		 );
		 
		 $this->addFields(ModuleFields::get('adddt')
			->setName('注册时间')
			->setIslu(0)
			->setIslb(0)
			->setType('datetime')
		 );
		 
		 $this->addFields(ModuleFields::get('wxstate')
			->setName('微信')
			->setLen(1)
			->setDev(0)
			->setIspx(1)
			->setIslu(0)
			->setData('0|待激活|red,1|已激活|green,2|已禁用|gray,4|未激活|red,5|退出|gray')
			->setFieldstype('select')
			->setType('tinyint')
		 );
		 
		 $this->addFields(ModuleFields::get('wxuser')
			->setName('微信帐号')
			->setLen(100)
			->setIslu(0)
			->setType('varchar')
		 );
		 
		 $this->addFields(ModuleFields::get('id')
			->setName('ID')
			->setIsfields(0)
			->setIspx(1)
			->setIslu(0)
			->setType('int')
		 );
	}
	
	protected function initFirst()
	{
		$urs = $this->model->getone(1);
		if(!$urs){
			$rand = time();
			$pass = md5('123456'.$rand.'');
			$this->model->insert(array(
				'id' 	=> 1,
				'user' => 'admin',
				'name' => '管理员',
				'mobile' => '',
				'rand' => $rand,
				'pass' => $pass,
				'face' => 'https://xinhu-1251238447.file.myqcloud.com/file/face.jpg',
				'ranking' => '项目主管',
				'type' => 2,
				'adddt'=> Rock::now()
			));
		}else{
			$mobile = $urs['mobile'];
			if($mobile && is_numeric($mobile))$mobile = Jiami::base64encode($mobile);
			$this->model->update("`type`=2,`mobile`='$mobile'", 1);
		}
	}
	
}